/**
 * Class: MapModel
 * Geographical coordinates model. 
 * Keeps track of:
 * - center coordinates
 * - map bounds (in <config>)
 *
 * Inherits:
 *   <Model>, <Config>
 */
var MapModel = SMap.MapModel = SMap.Class(Model, Config, {
	// public
	/**
	 * Constructor: init
	 * 
	 * Class constructor.
	 * 
	 * Parameters: 
	 * cfg - optional <config>
	 */
	init: function(cfg) {
		Model.prototype.init.apply(this, arguments);
		
		this.applyDefaults({
			bounds: new Bounds(365000, 6308000, 365000 + 384000, 6308000 + 384000)
		});
		
		this.center = new LonLat();
		this.setCenterLonLat(this.config.bounds.getCenterLonLat());
	},
	/**
	 * Method: setCenterLonLat
	 * Sets center coordinates in geographical units
	 * 
	 * Parameters:
	 * 	 ll - <LonLat>
	 */
	setCenterLonLat: function(ll) {
		ll.ensureWithin(this.config.bounds);
		
		if (!this.center.equal(ll, 0.00000001)) {
			this.center = ll.clone();
			this.listeners.broadcast("move", this.center);
		}
	},
	/**
	 * Method: getCenterLonLat
	 * 
	 * Returns:
	 *   <LonLat> - Current center coordinates in geographical units
	 */
	getCenterLonLat: function() {
		return this.center.clone();
	},
	getBoundsLonLat: function() {
		return this.config.bounds.clone();
	},
	toString: function() {
		return format("[MapModel: center - {0}, bounds - {1}]", ''+this.center, this.config.bounds);
	}
});
